package com.dzqc.fly.controller.mobile;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dzqc.fly.common.Kv;
import com.dzqc.fly.common.Result;
import com.dzqc.fly.db.form.*;
import com.dzqc.fly.db.pojo.SecretaryHomePojo;
import com.dzqc.fly.db.pojo.SecretaryStudentsPojo;
import com.dzqc.fly.db.pojo.StudentsLeavePojo;
import com.dzqc.fly.db.pojo.StudentsLeaveShenPiPojo;
import com.dzqc.fly.db.vo.SecretaryStudentDetailVo;
import com.dzqc.fly.db.vo.SecretaryStudentsTimeVo;
import com.dzqc.fly.db.vo.SecretarySumVo;
import com.dzqc.fly.service.SecretaryHomeService;
import com.dzqc.fly.service.SecretaryStudentsService;
import com.dzqc.fly.service.SecretarySumService;
import com.dzqc.fly.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Set;


/**
 * @author Administrator
 */


@RestController
@RequestMapping("/secretary/home")
@Tag(name = "SecretarySumController", description = "手机端用户Web接口")
@Slf4j
@EnableAutoConfiguration
public class SecretaryHomeController {

    @Autowired
    private UserService userService;
    @Autowired
    private SecretaryHomeService secretaryHomeService;

    @CrossOrigin
    //@GetMapping("/searchSecretaryHome")
    @RequestMapping(value="/searchSecretaryHome" ,method = RequestMethod.GET)
    @Operation(summary = "书记首页信息列表")
    @SaCheckLogin
    public Result searchSecretaryHome(@Valid SecretaryHomeForm secretaryHomeForm){
        HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= (HashMap) Kv.toKv(secretaryHomeForm);
        param.put("sno",userinfoMap.get("sno"));
        Page<SecretaryHomePojo> result=secretaryHomeService.searchSecretaryHome(param);
        return Result.commonOk(result);
    }
    //@GetMapping("/searchSecretaryHomeDetail")
    @RequestMapping(value="/searchSecretaryHomeDetail" ,method = RequestMethod.GET)
    @Operation(summary = "书记首页信息列表")
    @SaCheckLogin
    public Result searchSecretaryHome(@Valid SecretaryHomeDetailForm secretaryHomeDetailForm){
        //HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= (HashMap) Kv.toKv(secretaryHomeDetailForm);
        //param.put("sno",userinfoMap.get("sno"));
        StudentsLeaveShenPiPojo result=secretaryHomeService.searchSecretaryHomeDetail(param);
        return Result.commonOk(result);
    }


    @RequestMapping(value="/updateShenPi" ,method = RequestMethod.POST)
    @SaCheckLogin
    @Operation(summary = "书记端审批")
    public Result login(@Valid @RequestBody SecretaryShenPiForm secretaryShenPiForm){
       // HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= (HashMap) Kv.toKv(secretaryShenPiForm);
        //param.put("sno",userinfoMap.get("sno"));
        Integer result=secretaryHomeService.updateShenPi(param);
        if(result==1){
            return  Result.commonOk("审批成功");
        }else {
            return Result.commonOk("审批失败");
        }

    }

}
